/************************************************************************
Arise Engine		Singleton.h

					E-mail:	arise_engine@mail.ru

					Origin by Greg Snook: Real-Time 3D Terrain Engines 
					Using C++ and DirectX 9 

created:			03.02.2007
last changes:		03.02.2007
************************************************************************/
#pragma once


// disable the warning regarding 'this' pointers being used in 
// base member initializer list. Singletons rely on this action
//#pragma warning(disable : 4355)


template <class T>
class Singleton
{
public:

    // the singleton must be constructed
    // with a reference to the controlled object
    Singleton(T& rObject)
    {
		//debug_assert(!s_pInstance, "Only one instance of this class is permitted.");
        s_pInstance = &rObject;
    }

    // the singleton accessor
    ~Singleton()
    {
		//debug_assert(s_pInstance, "The singleton instance is invalid.");
        s_pInstance = 0;
    }

    // the singleton accessor
    static T& instance()
    {
		//debug_assert(s_pInstance, "The singleton has not yet been created.");
        return (*s_pInstance);
    }

private:

    // Data...
    static T* s_pInstance;

};
template <class T> T* Singleton<T>::s_pInstance = 0;

